package pers.jason.wppm.security.core.social.oicq;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;
import pers.jason.wppm.security.core.properties.SecurityProperties;
import pers.jason.wppm.security.core.social.oicq.connect.OicqOAuthConnectionFactory;

/**
 * @ClassName: OicqSocialConfig
 * @Author: JZH
 * @Date: 2018/11/25 1:26
 * 只有 配置属性 wppm.security.social.oicq.appId存在的时候才生效
 */
@Configuration
@ConditionalOnProperty(prefix = "wppm.security.social.oicq", name = "appId")
public class OicqSocialConfig extends SocialAutoConfigurerAdapter {

    @Autowired
    private SecurityProperties securityProperties;

    @Override
    protected ConnectionFactory<?> createConnectionFactory() {
        return new OicqOAuthConnectionFactory(
                securityProperties.getSocial().getOicq().getProviderId()
                , securityProperties.getSocial().getOicq().getAppId()
                , securityProperties.getSocial().getOicq().getAppSecret());
    }
}
